export function request(
    {
        url,
        method = 'post',
        data,
        headers = {},
        onProgress
    }) {
    return new Promise((resolve) => {
        const xhr = new XMLHttpRequest();

        xhr.upload.onprogress = onProgress;
        xhr.open(method, url);
        Object.keys(headers).forEach((key) =>
            xhr.setRequestHeader(key, headers[key])
        );
        xhr.send(data);
        xhr.onreadystatechange = function (e) {
            if (xhr.readyState == 4) {
                resolve({
                    data: e.target.response
                });
            }
        };
    });
}